// SendMsg2OtherProcess.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"

using namespace std;

HWND hWnd = 0;
HWND hSpecailWnd = 0;

WCHAR *className = L"TAQTreeView";

BOOL CALLBACK EnumWindowsProc(HWND h, LPARAM lParam)
{
	WCHAR name[20] = {0};
	GetClassName(h, name, 20);
	cout << name << endl;

	if(wcscmp(name, className) == 0)
	{
		hSpecailWnd = h;
		return true;
	}

	EnumChildWindows(h, EnumWindowsProc, 0);
	return true;
}

void getSpecialWnd()
{
	if (!hWnd)
		return;

	WCHAR name[20];
	GetClassName(hWnd, name, 20);
	cout << name << endl;
	EnumChildWindows(hWnd, EnumWindowsProc, 0);
}

int _tmain(int argc, _TCHAR* argv[])
{
	DWORD nThreadId = 0;
	DWORD nProcessId = 0;
	hWnd = FindWindow(L"TfrmMain", NULL);

	/*
	TCHAR titleText[MAX_PATH] = {0};
	HWND nHwnd = ::GetWindow(hWnd, GW_CHILD);
	while(nHwnd != NULL) {
		::GetWindowText(nHwnd, titleText, MAX_PATH);
		nHwnd = ::GetWindow(nHwnd, GW_HWNDNEXT);
	}
	*/

	if (hWnd)
	{
		getSpecialWnd();

		cout << "start..." << endl;

		int i = 0;
		Sleep(5000);
		while (i++ < 1000)
		{
			cout << "Post message" << endl;
			Sleep(10);
			PostMessage((HWND)(hSpecailWnd), WM_CHAR, VK_SPACE, 0);
			PostMessage((HWND)(hSpecailWnd), WM_KEYDOWN, VK_DOWN, 0);
		}
	}

	getchar();
	return 0;
}

